package main

import (
	"flag"
	"os"
	"time"

	"git.intra.weibo.com/platform/monitor"
	"github.com/naoina/toml"
	"github.com/songtianyi/rrframework/logs"
)

var (
	ratel     = flag.Duration("rl", 10*time.Second, "the duration to add a token for rate limiter")
	group     = flag.Bool("group", true, "只支持群聊，不支持单聊")
	dashboard = flag.String("dashboard", "dashboard.toml", "config file for monitored dashboards")
)

func main() {
	flag.Parse()

	logs.SetLevel(4)

	f, err := os.Open(*dashboard)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	var dashboards = make(map[int]monitor.Dashboard)
	if err := toml.NewDecoder(f).Decode(&dashboards); err != nil {
		panic(err)
	}

	s := monitor.NewServer(*ratel, *group, dashboards)
	for {
		if err := s.Serve(); err == nil {
			return
		}
	}

}
